<template>
  <div>
    <el-table v-loading="loading" :data="noticeList">
      <el-table-column label="项目描述" align="center" min-width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.projectDescribe || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="分类" align="center" prop="noticeType" min-width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.inspectionTypeNameParent || '-' }} - {{ scope.row.inspectionTypeNameChildren || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="状态" align="center" min-width="120">
        <template slot-scope="scope">
          <dict-tag :options="statusFlag" :value="scope.row.status" />
        </template>
      </el-table-column>
      <el-table-column label="归属" align="center" min-width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ ['-', '机房日常巡检', '线上巡检记录', '设备维护记录', '值班记录'][scope.row.ascription] || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="巡检结果类型" align="center" min-width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ ['-', '单选', '多选', '单项输入', '多项输入'][scope.row.resultType] || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="排序" align="center" min-width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.sort || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="创建用户" align="center" min-width="150" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.createBy || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="创建日期" align="center" min-width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.createTime || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="修改用户" align="center" min-width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.updateBy || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="修改日期" align="center" min-width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          {{ scope.row.updateTime || '-' }}
        </template>
      </el-table-column>
      <el-table-column label="操作" min-width="280" fixed="right" align="center" class-name="medium-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="small" v-hasPermi="['project_xg']" type="primary" icon="el-icon-edit"
            @click="handleUpdate(scope.row)">编辑</el-button>
          <!-- <el-button :disabled="!(scope.row.parentId === 0)" size="small" type="success" icon="el-icon-plus"
            @click="handleadd(scope.row)">新增
          </el-button> -->
          <el-button v-hasPermi="['project_dis']" v-if="scope.row.status === '0'" icon="el-icon-lock" size="small"
            type="danger" @click="handleDis(scope.row)">禁用
          </el-button>
          <el-button v-hasPermi="['project_dis']" v-else size="small" type="success" icon="el-icon-unlock"
            @click="handleDis(scope.row)">启用
          </el-button>
          <el-button v-hasPermi="['project_sc']" icon="el-icon-delete" size="small" type="danger"
            @click="handleDelete(scope.row)">删除
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- <div class="card-div"> -->
    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize"
      @pagination="getList" />
    <!-- </div> -->
    <!-- 修改设备基值 -->
    <template v-if="open">
      <AddbaseValue :title="title" :rowObj="rowObj"></AddbaseValue>
    </template>
  </div>
</template>

<script>
import { getinspectionprojectList, deletedinspectionproject, UpdateinspectionStatus } from "@/api/system/difftype.js";

export default {
  components: {
    AddbaseValue: () => import('../form/addbaseValue.vue'),
  },
  data () {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      dictdatalist: [],
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 弹出层表格数据
      noticeList: [],
      rowObj: {},
      // 弹出层标题
      title: "修改项目",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        orderByColumn: 'sort',
        isAsc: 'asc'//倒叙
        // isAsc: 'desc'//倒叙
      },
    };
  },
  created () {
    this.getList();
  },
  methods: {
    /** 查询列表 */
    async getList (value) {
      this.loading = true;
      let params = {
        ...this.queryParams,
        ...value
      }
      //  let data = await getdatalist({ dictType: 'base_unit' })
      //  this.dictdatalist=data.data
      getinspectionprojectList(params).then(response => {
        this.noticeList = response.data && response.data.map((item, index) => {
          return {
            ...item,
            order: index + 1
          }
        });
        this.total = response.total;
        this.loading = false;
      });
    },
    /** 修改按钮操作 */
    handleUpdate (row) {
      this.rowObj = row
      this.open = true
    },
    /** 启用禁用按钮操作 */
    handleDis (row) {
      this.$confirm(`是否确认${row.planStatus === '0' ? `禁用` : `启用`}该的数据？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.loading = true;
        let params = {
          id: row.id,
          status: row.status === '0' ? 1 : 0
        }
        UpdateinspectionStatus(params).then(res => {
          if (res.code === 200) {
            this.loading = false;
            this.$message.success(res.msg)
            this.getList()
          }
        }).catch(() => { this.loading = false; });
      }).catch(() => { this.loading = false; });
    },
    handleDelete (row) {
      this.$confirm(`是否确认删除该项目？`, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.loading = true;
        deletedinspectionproject(row.id).then(res => {
          if (res.code === 200) {
            this.$message.success(res.msg)
            this.getList()
          }
          this.loading = false;
        }).catch(() => { this.loading = false; });
      }).catch(() => { this.loading = false; });
    }
  },
  filters: {
  }
};
</script>
<style lang="scss" scoped>
.red {
  color: red;
}
</style>